# write by hasaki
# first edit on 2019-7-15
# last change on 2019-7-17
# 常鸿量化机版海龟策略
from datetime import datetime
import json

from hashakisea.strategy.haStrategyTemplate import HaStrategy
from hashakisea.signal.indicators import indicator

class HaTurtle(HaStrategy):
    def __init__(self):
        super(HaTurtle,self).__init__()
        self.symbol_max_pos=0            # 单品种最大持仓
        self.direction_max_pos=0         # 单方向最大持仓

        self.new_bar=None                # 最新的一条K线

        # 指标参数
        self.entryUp=None                # 进场通道
        self.entryDown=None
        self.exitUp=None                 # 出场通道
        self.exitDown=None

        self.entryWindow=0               # 进场通道周期数
        self.exitWindow=0                # 出场通道周期数

        self.atrVolatility = 0           # ATR波动率
        self.atrWindow = 0               # 计算ATR周期数

        self.K_list=[]                   # 用来保存计算指标的K线队列
    
    def next(self,data):
        pass
    
    def calculateIndicator(self):
        '''海龟策略计算指标，用到道其安通道和ATR指标'''
        self.entryUp, self.entryDown=indicator.donchian(self.K_list,self.entryWindow)
        self.exitUp, self.exitDown = indicator.donchian(self.K_list,self.exitWindow)

        # ATR波动率
        self.atrVolatility = indicator.atr(self.K_list,self.atrWindow)
